<template>
	<view class="container">
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="user.telephone" placeholder="请输入用户电话号码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<uni-easyinput v-model="user.password" type="password" placeholder="请输入用户密码" />
			</uni-forms-item>
			<uni-forms-item label="" name="">
				<button type="primary" @click="login">登录</button>
				<button type="default" @click="register">注册</button>
			</uni-forms-item>
		</uni-forms>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					telephone: "12345678912",
					password: "123456"
				}
			}
		},
		methods: {
			login(e) {



				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'POST',
					data: this.user,
					success: res => {

						if (res.data.success) {
							uni.clearStorageSync('user')

							uni.setStorageSync('user', res.data.data)

							uni.switchTab({
								url: '../my'
							})

						}

					},
					fail: (err) => {
						console.log(err);
					},
					complete: () => {
						uni.showToast({
							title: '用户电话号码或密码有误',
							icon: 'none'
						});
					}
				});
			},
			register(e) {
				uni.navigateTo({
					url: '../register/register'
				})
			}
		},
		onLoad: () => {


		}
	}
</script>

<style>

</style>
